package com.geekgo.ladder.core.aspect;

import org.apache.commons.lang.StringUtils;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author geekgo
 * @version 2016/12/19 16:44
 */
public class ChooseDataSource extends AbstractRoutingDataSource {

    public static Map<String,List<String>> METHODTYPE = new HashMap<String,List<String>>();
    //获取数据源名称
    @Override
    protected Object determineCurrentLookupKey() {
        return HandleDataSource.getDataSource();
    }
    //设置方法名前缀对应的数据源
    public void setMethodType(Map<String,String> map){
        for(String key:map.keySet()){
            List<String> value = new ArrayList<String>();
            String[] types = map.get(key).split(",");
            for(String type:types){
                if(StringUtils.isNotBlank(type)){
                    value.add(type);
                }
            }
            METHODTYPE.put(key,value);
        }
    }
}
